<?php

/**

 * Created by lihong.

 * Date: 2017/4/24

 * Time: 13:42

 */

    if (!defined('LEGAL_MARK')) {

        die('非法操作');

    }

    if(isLogin()){

        if(empty($_POST)){

            if(!empty($_GET['id'])){

                $id =$_GET['id'];

                $sql = 'select * from `about` where `id` ='.$id;

                $arrOne = hq_get_one($con,$sql);

                if(!empty($arrOne)){

                    if(!$arrOne){

                        die("数据出错!");

                    }

                }

                showHtml(

                    array(

                        'htmlTitle' => '公司介绍修改',

                        'arrOne' => $arrOne

                    ),

                    false

                );

            }else{

                showMsgAndLocation('非法参数!','index.php?'.ADMIN_MARK.'&c=about');

            }

        }else{

            $id = isset($_POST['id'])?(int)trim($_POST['id']):0;

            if(!$id){

                showMsgAndLocation('参数非法','index.php?'.ADMIN_MARK.'&c=about');

            }



            $sUpdateUrl = 'index.php?'.ADMIN_MARK.'&c=about&v=update&id='.$id;



            $class_name = trim($_POST['class_name']);

            if(empty($class_name)){

                showMsgAndLocation('请填写栏目名',$sUpdateUrl);

            }



            $info = clear_js($_POST['info']);

            if(empty($info)){

                showMsgAndLocation('请选择内容',$sUpdateUrl);

            }



            if($_FILES['cover_img']['error'] == 0) {

                //获取图片

                $img = upload_img($_FILES['cover_img'], $sUpdateUrl);

                $sql = 'select * from `water` limit 0,1';

                $water = hq_get_one($con,$sql);

                //裁剪图

                @img2thumb($img, get_thumb($img, '_thumb1'), $width = 580, $height = 290, $cut = 1, $proportion = 0);

                //设置水印

                @setWater($img, $water['markImg'], $water['markType'], $water['markPos'], $water['alpha'], $water['markText'], $water['TextColor']);

                @setWater(get_thumb($img, '_thumb1'), $water['markImg'], $water['markType'], $water['markPos'], $water['alpha'], $water['markText'], $water['TextColor']);

            }





            $time = time();

            if(!empty($img)) {

                $sql = 'update `about` set `class_name`=\'' . $class_name .

                    '\',`info`=\'' . $info .

                    '\',`cover_img`=\'' . $img .

                    '\',`u_time`=' . $time .

                    ' where `id` = ' . $id;

            }else{

                $sql = 'update `about` set `class_name`=\'' . $class_name .

                    '\',`info`=\'' . $info .

                    '\',`u_time`=' . $time .

                    ' where `id` = ' . $id;

            }





            $res = hq_query($con,$sql);



            if($res){

                get_html($con);

                if(!empty($img)){

                    $old_img = $_POST['old_img'];

                    @unlink($old_img);

                    @unlink(get_thumb($old_img,'_thumb1'));

                }

                showMsgAndLocation('更改介绍成功','index.php?' . ADMIN_MARK . '&c=about');

            }else{

                showMsgAndLocation('更改介绍失败',$sUpdateUrl);

            }

        }

    }else{

        showMsgAndLocation('请先登录','index.php?'.ADMIN_MARK.'&c=login');

    }

?>





